package com.hhkj.generator.util;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileReadUtil {

	public static List<String> readFileLine(File file) throws IOException{

		return readFileLine(file, "UTF-8");
	}

	public static List<String> readFileLine(File file, String charsetName) throws IOException{
		List<String> lineList = new ArrayList<String>();
		//BufferedReader是可以按行读取文件
		FileInputStream inputStream = new FileInputStream(file);
		BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(new FileInputStream(file),charsetName));

		String str = null;
		while((str = bufferedReader.readLine()) != null)
		{
			lineList.add(str);
		}

		//close
		inputStream.close();
		bufferedReader.close();

		return lineList;
	}

	public static String readAll(File file) throws IOException {
		List<String> lineList = readFileLine(file);
		StringBuffer sb = new StringBuffer();
		for (String line : lineList){
			sb.append(line);
		}

		return sb.toString();
	}

}
